home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / access1a / form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-14  |  10.3 KB  |  304 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  4. Begin VB.Form Form1 
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "ADO Connect to Access Databases"
  7.    ClientHeight    =   8595
  8.    ClientLeft      =   1815
  9.    ClientTop       =   1380
  10.    ClientWidth     =   11880
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   8595
  15.    ScaleWidth      =   11880
  16.    Begin MSComctlLib.StatusBar StatusBar1 
  17.       Align           =   2  'Align Bottom
  18.       Height          =   375
  19.       Left            =   0
  20.       TabIndex        =   16
  21.       Top             =   8220
  22.       Width           =   11880
  23.       _ExtentX        =   20955
  24.       _ExtentY        =   661
  25.       _Version        =   393216
  26.       BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
  27.          NumPanels       =   3
  28.          BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  29.             AutoSize        =   1
  30.             Bevel           =   2
  31.             Object.Width           =   15769
  32.             Text            =   "ADO Demo Program to copy Tables between Access Databases"
  33.             TextSave        =   "ADO Demo Program to copy Tables between Access Databases"
  34.          EndProperty
  35.          BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  36.             Style           =   5
  37.             Alignment       =   1
  38.             TextSave        =   "3:02 PM"
  39.             Object.Tag             =   "Time Field"
  40.          EndProperty
  41.          BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  42.             Style           =   6
  43.             Alignment       =   1
  44.             AutoSize        =   2
  45.             TextSave        =   "9/14/99"
  46.             Object.Tag             =   "date"
  47.          EndProperty
  48.       EndProperty
  49.    End
  50.    Begin MSComDlg.CommonDialog CommonDialog1 
  51.       Left            =   11040
  52.       Top             =   480
  53.       _ExtentX        =   847
  54.       _ExtentY        =   847
  55.       _Version        =   393216
  56.    End
  57.    Begin VB.Frame Frame1 
  58.       Caption         =   "ADO"
  59.       Height          =   7455
  60.       Left            =   240
  61.       TabIndex        =   0
  62.       Top             =   360
  63.       Width           =   10455
  64.       Begin VB.TextBox Text7 
  65.          Height          =   375
  66.          Left            =   600
  67.          TabIndex        =   15
  68.          Top             =   6360
  69.          Width           =   3855
  70.       End
  71.       Begin VB.TextBox Text6 
  72.          BackColor       =   &H80000000&
  73.          BorderStyle     =   0  'None
  74.          Height          =   285
  75.          Left            =   600
  76.          TabIndex        =   14
  77.          Text            =   "Enter the name of the Table to be copied to"
  78.          Top             =   5880
  79.          Width           =   3255
  80.       End
  81.       Begin VB.CommandButton Command7 
  82.          Caption         =   "<-"
  83.          Height          =   495
  84.          Left            =   3120
  85.          TabIndex        =   13
  86.          Top             =   3000
  87.          Width           =   495
  88.       End
  89.       Begin VB.CommandButton Command6 
  90.          Caption         =   "->"
  91.          Height          =   495
  92.          Left            =   3120
  93.          TabIndex        =   12
  94.          Top             =   2280
  95.          Width           =   495
  96.       End
  97.       Begin VB.ListBox List2 
  98.          Height          =   2010
  99.          ItemData        =   "Form1.frx":0000
  100.          Left            =   3960
  101.          List            =   "Form1.frx":0002
  102.          TabIndex        =   11
  103.          Top             =   2160
  104.          Width           =   2175
  105.       End
  106.       Begin VB.TextBox Text5 
  107.          Height          =   375
  108.          Left            =   600
  109.          TabIndex        =   10
  110.          Top             =   5040
  111.          Width           =   3855
  112.       End
  113.       Begin VB.CommandButton Command5 
  114.          Caption         =   "..."
  115.          Height          =   375
  116.          Left            =   4440
  117.          TabIndex        =   9
  118.          Top             =   5040
  119.          Width           =   375
  120.       End
  121.       Begin VB.TextBox Text4 
  122.          BackColor       =   &H80000000&
  123.          BorderStyle     =   0  'None
  124.          Height          =   375
  125.          Left            =   600
  126.          TabIndex        =   8
  127.          Text            =   "Select the database the table is to be copied to"
  128.          Top             =   4560
  129.          Width           =   3855
  130.       End
  131.       Begin VB.CommandButton Command3 
  132.          Caption         =   "Exit"
  133.          Height          =   495
  134.          Left            =   7440
  135.          TabIndex        =   7
  136.          Top             =   1920
  137.          Width           =   2175
  138.       End
  139.       Begin VB.CommandButton Command4 
  140.          Caption         =   "..."
  141.          Height          =   375
  142.          Left            =   4440
  143.          TabIndex        =   6
  144.          Top             =   960
  145.          Width           =   375
  146.       End
  147.       Begin VB.TextBox Text3 
  148.          Height          =   375
  149.          Left            =   600
  150.          TabIndex        =   5
  151.          Top             =   960
  152.          Width           =   3855
  153.       End
  154.       Begin VB.TextBox Text2 
  155.          BackColor       =   &H80000000&
  156.          BorderStyle     =   0  'None
  157.          Height          =   285
  158.          Left            =   600
  159.          TabIndex        =   4
  160.          Text            =   "Select the Database to copy from"
  161.          Top             =   480
  162.          Width           =   3855
  163.       End
  164.       Begin VB.ListBox List1 
  165.          Height          =   2010
  166.          ItemData        =   "Form1.frx":0004
  167.          Left            =   600
  168.          List            =   "Form1.frx":0006
  169.          TabIndex        =   3
  170.          Top             =   2160
  171.          Width           =   2175
  172.       End
  173.       Begin VB.CommandButton Command1 
  174.          Caption         =   "Copy Tables"
  175.          Height          =   495
  176.          Left            =   7440
  177.          TabIndex        =   2
  178.          Top             =   960
  179.          Width           =   2175
  180.       End
  181.       Begin VB.TextBox Text1 
  182.          BackColor       =   &H80000000&
  183.          BorderStyle     =   0  'None
  184.          Height          =   165
  185.          Left            =   600
  186.          TabIndex        =   1
  187.          Text            =   "Select a Table from the selected database"
  188.          Top             =   1680
  189.          Width           =   3375
  190.       End
  191.    End
  192. Attribute VB_Name = "Form1"
  193. Attribute VB_GlobalNameSpace = False
  194. Attribute VB_Creatable = False
  195. Attribute VB_PredeclaredId = True
  196. Attribute VB_Exposed = False
  197. Private Sub Command1_Click()
  198. Dim cnn1 As ADODB.Connection
  199. Dim cmdQuery As ADODB.Command
  200. Dim strCnn As String
  201. Dim Rs1 As ADODB.Recordset
  202. Dim prm As ADODB.Parameter
  203. Dim First, UserPath As String
  204. 'error handler
  205. On Error GoTo ErrorHandler
  206. sTable = List2.List(0)  ' the table we are going to copy
  207. ' ADO connection string that MS uses to to setup a link between
  208. ' the program and a JET database
  209. ' the string would be different for non JET DB's such as Oracle.
  210. strCnn = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source="
  211. strCnn = strCnn & sTmp
  212. ' create and open a connection to the databse
  213. Set cnn1 = New ADODB.Connection
  214. cnn1.Open strCnn
  215. ' declare working variables we'll need for executing SQL statements
  216. Set cmdQuery = New ADODB.Command
  217. Set Rs1 = New ADODB.Recordset
  218. 'active connection
  219. Set cmdQuery.ActiveConnection = cnn1
  220. ' build the query up
  221. SelectString = "SELECT * INTO"
  222. FromString = "FROM"
  223. FromSource = sTmp
  224. NewTable = Text7.Text
  225. 'builds up query that will copy tables and data
  226. SQLtext = SelectString & Space(1) & "[" & Destination & "]" _
  227.             & "." & NewTable & Space(1) & FromString & Space(1) _
  228.             & "[" & FromSource & "]" & "." & sTable
  229. ' assigns the SQL statement to the command object
  230. cmdQuery.CommandText = SQLtext
  231. ' runs the SQL statement
  232. Set Rs1 = cmdQuery.Execute()
  233. If Err.Number = 0 Then
  234.     MsgBox "The copy of Tables is complete. So There!!", vbOKOnly, "ADO Copy System Message"
  235. End If
  236. 'close the connection to the database
  237. cnn1.Close
  238. Exit Sub
  239. ErrorHandler:   ' Error-handling routine.
  240.    Select Case Err.Number   ' Evaluate error number.
  241.        
  242.        Case Else
  243.          
  244.       Msg = "Unexpected error #" & Str(Err.Number)
  245.       Msg = Msg & " occurred: " & Err.Description
  246.       ' Display message box with Stop sign icon and
  247.       ' OK button.
  248.       MsgBox Msg, vbCritical
  249.       
  250.    End Select
  251.    Resume Next  ' Resume execution at same line
  252.             ' that caused the error.
  253. End Sub
  254. Private Sub Command3_Click()
  255. End Sub
  256. Private Sub Command4_Click()
  257. ' the database to copy from
  258. ' sets up a common dialog box that will only show Access .mdb files
  259.   CommonDialog1.Filter = "DB Files" & _
  260.   "(*.mdb)|*.mdb"
  261. CommonDialog1.ShowOpen
  262.   If Err = 32755 Then         ' if the user has cancelled
  263.     Exit Sub
  264.   Else
  265.     sTmp = CommonDialog1.FileName    'get the filename selected by the user
  266.     Text3.Text = sTmp
  267.     Set dbList = Workspaces(0).OpenDatabase(sTmp)
  268.     List1.Clear
  269.     For Each tdFrom In dbList.TableDefs
  270.         '  screen out all tables beginning with MSys as they are not needed
  271.        If Mid(tdFrom.Name, 1, 4) <> "MSys" Then
  272.        
  273.             List1.AddItem tdFrom.Name   ' add the name of the table to the List
  274.        
  275.        End If
  276.     Next
  277.   End If
  278. End Sub
  279. Private Sub Command5_Click()
  280. ' the database to copy to
  281. ' sets up a common dialog box that will only show Access .mdb files
  282. CommonDialog1.Filter = "DB Files" & _
  283.   "(*.mdb)|*.mdb"
  284. CommonDialog1.ShowOpen
  285.   If Err = 32755 Then    ' if the user has cancelled
  286.     Exit Sub
  287.   Else
  288.     Destination = CommonDialog1.FileName  'get the filename selected by the user
  289.     Text5.Text = Destination   ' and display it
  290.    End If
  291. End Sub
  292. Private Sub Command6_Click()
  293. ' writes the selected Table name from List1 to List2
  294. List2.AddItem List1.Text
  295. End Sub
  296. Private Sub Command7_Click()
  297. 'takes out the Table name entry in List2
  298. List2.RemoveItem (0)
  299. End Sub
  300. Private Sub List1_DblClick()
  301. ' writes the selected Table name from List1 to List2
  302. List2.AddItem List1.Text
  303. End Sub
  304.